package com.ykq.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ykq.anotation.PreAuthoritory;
import com.ykq.core.entity.User;
import com.ykq.core.util.JWTUtil;
import com.ykq.core.util.WebUtil;
import com.ykq.core.vo.R;
import com.ykq.system.service.UserService;
import com.ykq.system.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: 闫克起
 * @Description:
 * @Date: Create in 11:56 2024/8/12
 */
@RestController
@RequestMapping("/system/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/getByName/{name}")
    public R<User> getByName(@PathVariable String name){
        return userService.selectByName(name);
    }

    @GetMapping("/info")
    public R<User> info(){
        String token = WebUtil.getRequest().getHeader("token");
        Object username = JWTUtil.getInfo(token).get("username");
        return userService.selectByName(username.toString());
    }

    @PostMapping("/listByPage")
    public R<IPage<User>> list(@RequestBody UserVo userVo){
        return userService.selectByPage(userVo);
    }

    @GetMapping("/batchDelete")
    public R batchDelete(Long[] userIds){

        return userService.batchDelete(userIds);
    }

    @PostMapping("findSchedulingUser")
    public R<List<User>> findSchedulingUser(@RequestBody Map<String,Object> params){
        return userService.selelctSchedulingUser(params);
    }

    @GetMapping("/list")
    public R<List<User>> list(){
        return userService.selectAll();
    }
}
/**
 * 自己配置权限校验的功能。 Aop  注解
 */














